﻿using Library.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library.Core.Services
{
    public class LibraryAsyncService
    {
        private readonly LibraryService core = new LibraryService();

        public Task<bool> BorrowBookAsync(int readerId, int bookId)
            => Task.Run(() => core.BorrowBook(readerId, bookId));

        public Task<decimal> ReturnBookAsync(int readerId, int bookId, Action<bool> onOverdue)
            => Task.Run(() =>
            {
                bool wasOverdue;
                var fine = core.ReturnBook(readerId, bookId, out wasOverdue);
                onOverdue?.Invoke(wasOverdue);
                return fine;
            });

        public Task<bool> RenewBookAsync(int readerId, int bookId)
            => Task.Run(() => core.RenewBook(readerId, bookId));

        public Task<List<Reader>> GetBlacklistedAsync()
            => Task.Run(() => core.GetBlacklistedReaders());

        public Task<bool> RestoreReaderAsync(int readerId)
            => Task.Run(() => core.RestoreReader(readerId));

        public void Seed() => core.Seed();
        public void CheckOverdues() => core.CheckOverdues();
    }
}
